#include <iostream>
#include <sstream>
#include <fstream>
#include <sys/resource.h>
#include "SAW.h"

using namespace std;

/*
 * argv[1] amount of stepsizes
 * argv[2..argv[1]] the stepsizes
 * argv[argv[1]+2] the seed
 * argv[argv[1]+3] amount of walks
 * argv[argv[1]+4] id
 */
int main(int argc, char** argv) {
    stringstream ss;
    ss << argv[1];

    unsigned long amountStepsizes;
    ss >> amountStepsizes;
    ss.clear();
    ss.str("");

    unsigned long* stepsizes = new unsigned long[amountStepsizes];
    for (size_t i = 0; i < amountStepsizes; ++i) {
        ss << argv[i + 2];
        ss >> stepsizes[i];
        ss.clear();
        ss.str("");
    }

    unsigned int seed;
    ss << argv[amountStepsizes + 2];
    ss >> seed;
    ss.clear();
    ss.str("");

    size_t amountOfWalks;
    ss << argv[amountStepsizes + 3];
    ss >> amountOfWalks;
    ss.clear();
    ss.str("");

    ss << "/dev/shm/log" << argv[amountStepsizes + 4];
    ofstream file(ss.str().c_str());
    SAW* saw = new SAW(stepsizes, amountStepsizes, seed);
    long unsigned length = 0;
    for (size_t i = 0; i < amountOfWalks; ++i) {
        length = saw->walk();
        if (length == 0) {
            file << "NaN" << endl;
        } else {
            file << length << endl;
        }
    }
    file.close();

    return 0;
}
